package com.bw.miaosha.web;

import com.bw.miaosha.dao.GoodsDao;
import com.bw.miaosha.dao.MiaoshaActivityDao;
import com.bw.miaosha.entity.GoodsEntity;
import com.bw.miaosha.entity.MiaoshaActivityEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 朱财艺
 * @date : 2022/02/22
 * @Description:
 */
@Controller
public class WebController {

    @Autowired
    private MiaoshaActivityDao miaoshaActivityDao;

    @Autowired
    private GoodsDao goodsDao;

    @RequestMapping("/list")
    public String list(Model model){

        List<MiaoshaActivityEntity> miaoshaActivityEntities = miaoshaActivityDao.selectList(null);
        for (MiaoshaActivityEntity miaoshaActivityEntity : miaoshaActivityEntities) {
            Long goodsId = miaoshaActivityEntity.getGoodsId();
            GoodsEntity goodsEntity = goodsDao.selectById(goodsId);
            ArrayList<GoodsEntity> goodsEntitiess = new ArrayList<>();
            goodsEntitiess.add(goodsEntity);
            miaoshaActivityEntity.setList(goodsEntitiess);
        }

        model.addAttribute("goods",miaoshaActivityEntities);
        return "index";
    }
}
